package com.example.robertluozizhao.framecollectdemo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.robertluozizhao.framecollectdemo.R;
import com.example.robertluozizhao.framecollectdemo.common.manager.ProxyManager;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Lzz on 4/11/2020.
 */

public class ReflectTestActivity extends Activity implements View.OnClickListener{

    @BindView(R.id.btn_bs_one)
    Button mBtnBsOne;
    @BindView(R.id.btn_bs_two)
    Button mBtnBsTwo;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reflect_test);
        ButterKnife.bind(this);



        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();

                Handler handler = new Handler(new Handler.Callback() {
                    @Override
                    public boolean handleMessage(Message msg) {
                        return false;
                    }
                });

                handler.sendMessage(new Message());

                Looper.loop();
            }
        }).start();


//        mBtnBsOne.setOnClickListener(new ClickClientOne());//委托类（1.专注于业务）
//        mBtnBsTwo.setOnClickListener(new ClickClientTwo());//委托类

//        View.OnClickListener listenOne = getListen(new ClickClientOne());
//        View.OnClickListener listenTwo = getListen(new ClickClientTwo());
//        Log.d("ReflectTestActivity ", "onCreate: listenOne:"+listenOne+",listenTwo:"+listenTwo);
        mBtnBsOne.setOnClickListener(ProxyManager.getInstance().getListen(this,1));//代理类对象（1.不影响原业务功能，进行扩展功能；2.原业务与新加逻辑功能无耦合）
        mBtnBsTwo.setOnClickListener(ProxyManager.getInstance().getListen(this,2));//代理类对象
    }



    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_bs_one:
                Toast.makeText(getApplicationContext(),"执行了业务一",Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_bs_two:
                Toast.makeText(getApplicationContext(),"执行了业务二",Toast.LENGTH_SHORT).show();
                break;
            default:
                throw  new RuntimeException("xxxxxxx！");
        }
    }




    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
